﻿using Newtonsoft.Json;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RDWSMTool.ViewModels.Dialogs
{
    public class AddGoodsDialogViewModel : BindableBase, IDialogAware
    {
        private string code;
        public string Code
        {
            get { return code; }
            set { SetProperty(ref code, value); }
        }
        private string name;
        public string Name
        {
            get { return name; }
            set { SetProperty(ref name, value); }
        }
        private string model;
        public string Model
        {
            get { return model; }
            set { SetProperty(ref model, value); }
        }
        private int count;
        public int Count
        {
            get { return count; }
            set { SetProperty(ref count, value); }
        }
        private string unit;
        public string Unit
        {
            get { return unit; }
            set { SetProperty(ref unit, value); }
        }
        private string pos1;
        public string Pos1
        {
            get { return pos1; }
            set { SetProperty(ref pos1, value); }
        }
        private string pos2;
        public string Pos2
        {
            get { return pos2; }
            set { SetProperty(ref pos2, value); }
        }
        private string pos3;
        public string Pos3
        {
            get { return pos3; }
            set { SetProperty(ref pos3, value); }
        }
        private ObservableCollection<string> unitList;
        public ObservableCollection<string> UnitList
        {
            get { return unitList; }
            set { SetProperty(ref unitList, value); }
        }
        private DelegateCommand<object> buttonCommand;
        public DelegateCommand<object> ButtonCommand =>
            buttonCommand ?? (buttonCommand = new DelegateCommand<object>(ExecuteButtonCommand));
    

        public string Title => "添加物料";

        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            Code = parameters.GetValue<string>("Code");
            Name = parameters.GetValue<string>("Name");
            Model = parameters.GetValue<string>("Model");
            Count = 0;
            Unit = parameters.GetValue<string>("Unit");
            Pos1 = "";
            Pos2 = "";
            Pos3 = "";

        }
        public virtual void RaiseRequestClose(IDialogResult dialogResult)
        {
            RequestClose?.Invoke(dialogResult);
        }
        void ExecuteButtonCommand(object obj)
        {
            switch (obj.ToString())
            {
                case "0":
                    {
                        DialogParameters param = new DialogParameters();
                        param.Add("Code", Code);
                        param.Add("Name", Name);
                        param.Add("Model", Model);
                        param.Add("Count", Count);
                        param.Add("Unit", Unit);
                        param.Add("Pos1", Pos1);
                        param.Add("Pos2", Pos2);
                        param.Add("Pos3", Pos3);
                        RaiseRequestClose(new DialogResult(ButtonResult.Yes, param));
                    }
                    break;
                case "1":
                    {
                        RaiseRequestClose(new DialogResult(ButtonResult.No));
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
